package com.zhsm.fuxi.mvp.ui.dialog

import android.content.Context
import android.view.View
import com.hankkin.reading.control.UserControl
import com.zhsm.fuxi.R
import com.zhsm.fuxi.base.BaseDialog
import kotlinx.android.synthetic.main.dialog_att_pay.*
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by GuZhC on 2018/11/05.
 * describe:缴纳押金弹窗
 */
class AttPayDialog(context: Context) : BaseDialog(context) {

    var isPay = false
    var money = UserControl.getCurrentUser()?.needDepositAmount
    override fun getLayoutId(): Int {
        return R.layout.dialog_att_pay
    }

    override fun getGravity(): Int {
        return BaseDialog.GRAVITY_BOTTOM
    }

    override fun isCanceledOnTouchOutside(): Boolean {
        return false
    }

    override fun initView() {
        super.initView()
        payView.visibility = View.VISIBLE
        closeView.visibility = View.GONE
        attPayNum.text = money
        addCashPledge.text = "缴纳押金$money"
        setClick()
    }


    fun setClick() {
        attPayZfb.onClick {
            attPayWeixin.isChecked = false
            attPayZfbCb.isChecked = true
        }
        attPayWx.onClick {
            attPayWeixin.isChecked = true
            attPayZfbCb.isChecked = false
        }
        addCashPledge.onClick {
            if (isPay){
                dismiss()
            }else{
                if (attPayZfbCb.isChecked) {
                    if (::onClickZfbPay.isInitialized)
                        onClickZfbPay.invoke()
                } else {
                    if (::onClickWxPay.isInitialized)
                        onClickWxPay.invoke()
                }
            }
        }
    }

    fun paySucess() {
        isPay = true
        payView.visibility = View.GONE
        closeView.visibility = View.VISIBLE
        addCashPledge.text = "关闭"
    }

    lateinit var onClickZfbPay: () -> Unit
    lateinit var onClickWxPay: () -> Unit
}